package com.atguigu.category.controll;

import com.atguigu.category.service.CategoryService;
import com.atguigu.param.ProductHotParam;
import com.atguigu.utils.R;
import org.apache.http.conn.util.PublicSuffixList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName:Category
 * Package:com.atguigu.category.controll
 * Description:
 *
 * @Author 应永豪
 * @Create 2024/4/21 20:48
 * @Version 1.0
 */
@RestController
@RequestMapping("category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;
    @GetMapping("/promo/{categoryName}")
    public R byName(@PathVariable String categoryName){
        if (StringUtils.isEmpty(categoryName)){
            return R.fail("类别名称为null,无法查询类别数据");
        }
        return categoryService.byname(categoryName);
    }


    @PostMapping("hots")
    public R hotsCategory(@RequestBody @Validated ProductHotParam param, BindingResult bindingResult){
        if (bindingResult.hasErrors()){

            return R.fail("类别集合查询失败");
        }

        return categoryService.hotsCategory(param);
    }

    @GetMapping("list")
    public R list(){
        return categoryService.list();
    }



}
